package com.auerdi.dialog;

import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.auerdi.AnimationUtils.AnimationUtils;
import com.auerdi.R;
import com.auerdi.ui.account.ADLoginFragment;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by highsixty on 2018/3/15.
 * mail  gaolulin@sunmi.com
 */

public class CheckLoginDialog extends AppCompatDialogFragment {


    Unbinder unbinder;
    @BindView(R.id.container)
    LinearLayout container;
    @BindView(R.id.phone_login)
    TextView phoneLogin;
    @BindView(R.id.phone_regit)
    TextView phoneRegit;
    private View mView;

    public CheckLoginDialog() {
        super();
    }


    public static CheckLoginDialog newInstance() {

        Bundle args = new Bundle();

        CheckLoginDialog dia = new CheckLoginDialog();
        dia.setArguments(args);
        return dia;
    }


    @Override
    public Dialog getDialog() {

        return super.getDialog();
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return super.onCreateDialog(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
//        getDialog().getWindow().getAttributes().windowAnimations = R.style.alert_dialog;
//        dialog.getWindow().setWindowAnimations(R.style.alert_dialog); //设置窗口弹出动画
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.doalog_check_login, container, false);


        unbinder = ButterKnife.bind(this, view);
        phoneLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(ADLoginFragment.newInstance());
                dismiss();
            }
        });
        AnimationUtils.slideToUp(view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }


    @Override
    public void onDestroyView() {


        super.onDestroyView();

        unbinder.unbind();
    }


    @Override
    public void dismiss() {
        super.dismiss();
    }


    @OnClick(R.id.container)
    public void onViewClicked() {
//        AnimationUtils.collapse(mView);
//        dismiss();

    }

}
